package woa.sort;

import java.util.Arrays;

/**
 * 插入排序
 *
 * @author wangpeng
 * @date 2022/1/10
 */
public class InsertSort {

    public static void main(String[] args) {
        int[] arr = new int[]{4,3,1,2,71};
        for (int i = 1; i < arr.length; i++) {
            int val = arr[i];
            int j = i - 1;
            for (; j >= 0; j--) {
                if (arr[j] > val) {
                    arr[j + 1] = arr[j];
                } else {
                    break;
                }
            }
            arr[j + 1] = val;
        }

        System.out.println(Arrays.toString(arr));
    }
}
